﻿var arr = ["#85ACFC", "#FB9F7A", "#FF7C89", "#69CAF4", "#D256FC", "#89D151", "#56B1EA", "#FF82BA", "#FE9D78", "#F15352", "#3BBE80", "#9AE35D", "#5ECE68", "#56B1EA", "#FF7C89", "#D457FD", "#85ACFC", "#FB9F7A", "#FF7C89", "#69CAF4", "#D256FC", "#89D151"];

var arr1 = ["#D256FC", "#89D151", "#56B1EA", "#F15352", "#56B1EA", "#D256FC", "#89D151", "#56B1EA", "#FB9F7A", "#9AE35D", "#5ECE68", "#56B1EA", "#D256FC", "#89D151", "#56B1EA", "#FF82BA", "#FE9D78", "#F15352", "#3BBE80", "#D256FC", "#89D151", "#9AE35D"];
 

var num = 0;
var num1 = 0;
var listid = "";
var arrlistid = "";

$(document).ready(function () {

    try {
        listid = getCookie("chanid");
        arrlistid = listid.split(',');
    }
    catch (e) { }
    Sreachlist();
});

function Sreachlist() {

    ajax.Getchelist("page_index=1", function (data) {
        if (data.msg.toString() == "成功") {
            $(data.item.table).each(function () {
                //频道排序前六个为默认频道
                if (num < 6) {
                    $(".serachList").append("<div class=\"serachitme " + this.id + "\" ><div class=\"searchTag\" style=\"background-color:" + arr[num] + ";\">" + this.name + "</div></div>");
                    num++;
                }
                else {
                    //cookie记录的默认频道
                    if (isbool(this.id)) {
                        $(".serachList").append("<div class=\"serachitme " + this.id + "\"   onclick=\"f(" + this.id + "); return false;\"><div class=\"searchTag\" style=\"background-color:" + arr[num] + ";\">" + this.name + "</div></div>");
                        num++;
                    }
                    else {
                        $(".serachLists").append("<div class=\"serachitme " + this.id + "\"   onclick=\"f2(" + this.id + ");\"><div class=\"searchTag\" style=\"background-color:" + arr1[num1] + ";\">" + this.name + "</div></div>");
                        num1++;
                    }
                }
            });

        }
    });

}
function f(value) {
    if ($("#serachList ." + value).is(":animated")) { return;  }
    if ($("#serachList ." + value).children().css("display") == "none") return;
    numleth();
    $(".serachLists").append(" <div class=\"serachitme " + value + "\"  onclick=\"f2(" + value + "); return false;\"><div class=\"searchTag\" style=\"display:none;background-color:" + arr[num] + ";\">" + $("#serachList ." + value).children().html() + "</div></div>");
    num++;
    var X = $("#serachList ." + value).offset().top;
    var X1 = $("#serachLists ." + value).offset().top;
    var Y = $("#serachList ." + value).offset().left;
    var Y1 = $("#serachLists ." + value).offset().left;
    $("#serachList ." + value).animate({ left: Y1 - Y + 'px', top: (X1 - X) + 'px' }, 500, function () { $("#serachList ." + value).remove(); $("#serachLists ." + value).children().css("display", "block"); setcookielist(); });
   // $("#serachList ." + value).fadeOut(300);
   

 }

 function f2(value) {
     if ($("#serachLists ." + value).is(":animated")) { return;}
     if ($("#serachLists ." + value).children().css("display") == "none") return;
     numsleth();
     $(".serachList").append("<div class=\"serachitme " + value + "\"   onclick=\"f(" + value + "); return false;\"><div class=\"searchTag\" style=\" display:none; background-color:" + arr1[num1] + ";\">" + $("#serachLists ." + value).children().html() + "</div></div>");
     num1++;

     var X1 = $("#serachList ." + value).offset().top;
     var X = $("#serachLists ." + value).offset().top;
     var Y1 = $("#serachList ." + value).offset().left;
     var Y = $("#serachLists ." + value).offset().left;


     $("#serachLists ." + value).animate({ left: Y1 - Y + 'px', top: (X1 - X) + 'px' }, 500, function () { $("#serachLists ." + value).remove(); $("#serachList ." + value).children().css("display", "block"); setcookielist(); });
 
//     $("#serachLists ." + value).fadeOut(300);
//     $("#serachLists ." + value).remove();
    
 }
 //循环颜色
 function numleth() {
     if (arr.length-1 < num)
         num = 0;
 }
 //循环颜色
 function numsleth() {
     if (arr1.length-1 < num1)
         num1 = 0;
 }
 //设置cookie
 function setcookielist() {
     var chanid = "";
     $(".serachList").children().each(function (i, n) {
    
         if ($(n).attr("onclick") != undefined) {
             chanid += $(n).attr("class").split(' ')[1] + ",";
         }
     });
 
     chanid = chanid.substr(0, chanid.length - 1);
     SetCookie("chanid", chanid);
 }

     //是否cookie记录的频道
 function isbool(id) {
 
         if (arrlistid[0] != undefined) {
             for (var i = 0; i <arrlistid.length; i++) {
                 if (id == arrlistid[i]) {
                     return true;
                 }
             }
         }
         return false;
     }